package com.example.cpoopc.helloretrofit.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * audio数据格式
 * 
 * <br>Created 2014-8-21 下午3:37:51
 * @version  
 * @author   chenpeng		
 *
 * @see
 */
public class AudioInfo implements Parcelable{
    public String path;// 文件路径
    public String time;// 语音长度
    public long timeMs;// 用于拼接url
    public long fid;// 用于拼接url
    public long tid;// 所属帖子id
    
    public AudioInfo(String time, long fid) {
        super();
        this.time = time;
        this.fid = fid;
    }
    
    
    
    public AudioInfo(String path, long timeMs, long fid) {
        super();
        this.path = path;
        this.timeMs = timeMs;
        this.fid = fid;
    }



    private AudioInfo (Parcel source){
        time = source.readString();
        fid = source.readLong();
    }

    public static final Creator<AudioInfo> CREATOR = new Creator<AudioInfo>() {
        
        @Override
        public AudioInfo[] newArray(int size) {
            return new AudioInfo[size];
        }
        
        @Override
        public AudioInfo createFromParcel(Parcel source) {
            return new AudioInfo(source);
        }
    };
    
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(time);
        dest.writeLong(fid);
    }
    
    public JSONArray toJsonArray() throws JSONException{
        JSONArray ja = new JSONArray();
        JSONObject jb = new JSONObject();
        if(!TextUtils.isEmpty(path)){
            jb.put("path", path);
        }
        jb.put("time", time);
        jb.put("fid", fid);
        ja.put(jb);
        return ja;
    }
    
}
